<?php ob_start();
if(!isset($_SESSION)){
session_start(); 
$message="";
}
	require_once('../../include/inc_config.php') ;
	//echo retourValForm('num');
	
	// l'utilisateur a cliqué sur le bouton Retour  de l'�cran de souscription
	if(isset($_GET['retour']) && $_GET['retour']==1  && isset($_SESSION['num_contrat']) && isset($_SESSION['MM_Username']))
	{
		$msg="";
		$requete	=	mysql_query("select * from agent where Code_agent='".$_SESSION['MM_Username']."'");
				$reponse	=	mysql_fetch_array($requete);
				$idagent	=	$reponse["Identifiant_agent"];
				
		$requete=mysql_query("select * from contrat where Numero_contrat='".$_SESSION['num_contrat']."'");
				$reponse	=	mysql_fetch_array($requete);
				$idcontrat	=	$reponse["Identifiant_contrat"];
		
			//cr�ation evenement souscription contrat 
			$req=mysql_query("select * from evenement where Type_evenement='G' and Sous_type_evenement='AMA' and Motif_evenement='' and Reference_evenement='' and Date_evenement='".date('Y-m-d')."' and Identifiant_agent='".$idagent."' and Identifiant_sinistre='' and Identifiant_contrat='".$idcontrat."' and Identifiant_personne='' and Identifiant_echeance='' and Identifiant_prestation=''") or die(mysql_error());
			$n=-1;
			if($req)
			{
				$n=mysql_num_rows($req);
			}
			//$requete=false;
			if($n==0)
			{
				mysql_query("START TRANSACTION");
                $oEvent = new dataObject_evenement() ;
                $requete = $oEvent->evenement_insertAMA($idcontrat) ;
				//$requete=mysql_query("insert into evenement values('','G','AMA','','','".date('Y-m-d')."','".$idagent."','','".$idcontrat."','','','')")or die(mysql_error());
				/*
                    $zSql  = " INSERT INTO evenement" ;
                    $zSql .= " (Type_evenement, Sous_type_evenement, Date_evenement, Identifiant_agent )" ;
                    $zSql .= " VALUES " ;
                    $zSql .= " ('G', 'AMA', '" . date('Y-m-d') . "', '" . $idagent . "')" ;
                    $requete=mysql_query($zSql)or die(mysql_error());
                 */
				// $requete=mysql_query("insert into evenement values('','G','AMA','','','".date('Y-m-d')."','".$idagent."','','".$_SESSION['idcontrat']."','','','')")or die(mysql_error());
						if(!$requete)
						{
							mysql_query("rollback");
							// --- $_SESSION['num_contrat']=NULL;
							unset($_SESSION['num_contrat']);
							session_destroy();mysql_query("rollback");
                            // --- echo 45 . '---' ;
							header("location:../../menu.php?ajouteventmodadmin=0");
						}else{
							mysql_query("commit");
							// --- $_SESSION['num_contrat']=NULL;
							// --- unset($_SESSION['num_contrat']);
							//session_destroy();
							//echo 51 . '---' ;
							// --- header("location:../../menu.php");
						}
			}
	}
?>
<?php
	
$currentPage = $_SERVER["PHP_SELF"];

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}


$maxRows_rs1 = 10;
$pageNum_rs1 = 0;
if (isset($_GET['pageNum_rs1'])) {
  $pageNum_rs1 = $_GET['pageNum_rs1'];
}
$startRow_rs1 = $pageNum_rs1 * $maxRows_rs1;

$colname_rs1 = "-1";

if ((isset($_POST["MM_rechercher"])) && ($_POST["MM_rechercher"] == "form1") || isset($_SESSION['num_contrat'])) {
	
	if(isset($_POST['Numero_contrat']) && !empty($_POST['Numero_contrat'])) {
		
	$colname_rs1 = IdContrat($database_microassur, $microassur, retourValForm('Numero_contrat'));
    
		// --- $_SESSION['num_contrat']=NULL;
		// --- unset($_SESSION['num_contrat']); 
		$_SESSION['num_contrat'] = $_POST['Numero_contrat'];
		$_SESSION['idcontrat'] = $colname_rs1;
	}
    elseif (array_key_exists ('num_contrat', $_SESSION)) 
    {
		$colname_rs1 = IdContrat($database_microassur, $microassur, $_SESSION['num_contrat']);
		$sess_con = $_SESSION['num_contrat'];
	}
    
	mysql_select_db($database_microassur, $microassur);
	$query_rs1 = sprintf("SELECT * FROM `role`  WHERE `Etat_role` = 'A' AND `Identifiant_contrat` = %s", GetSQLValueString($colname_rs1, "int"));
	//$query_limit_rs1 = sprintf("%s LIMIT %d, %d", $query_rs1, $startRow_rs1, $maxRows_rs1);
	$query_limit_rs1 = $query_rs1;
	$rs1 = mysql_query($query_limit_rs1, $microassur) or die(mysql_error());
	$row_rs1 = mysql_fetch_assoc($rs1);
    
	/* var_dump($colname_rs1);*/ 
	
	if (isset($_GET['totalRows_rs1'])) {
	  $totalRows_rs1 = $_GET['totalRows_rs1'];
	}elseif($colname_rs1==-1 ){
		$message = colorer("Vous devez saisir le num&eacute;ro de contrat","false");
	}elseif( $colname_rs1==NULL){
		$message = colorer("Contrat inexistant","false");
	}
	else {
		$all_rs1 = mysql_query($query_rs1);
		$totalRows_rs1 = mysql_num_rows($all_rs1);
		if($totalRows_rs1 == 0)
        {
            $message = colorer("Contrat inexistant","false");
        }
		else
        {
            $totalPages_rs1 = ceil($totalRows_rs1/$maxRows_rs1)-1;
        }
	}
	
	$etatContrat = EtatContrat($database_microassur, $microassur, retourValForm('Numero_contrat'));
	if($etatContrat == 'R'){
		$message = colorer("Vous ne pouvez pas modifier  un contrat r&eacute;sili&eacute;","false");
	}

}
/* if(isset($_GET['id']) && $_GET['id']=='ok' ){
			$requete=mysql_query("insert into evenement values('','G','AMA','','','".date('Y-m-d')."','".$_SESSION["MM_Username"]."','','".$_SESSION['idcontrat']."','','','')")or die(mysql_error());
				if($requete)header("location:index.php?&ajevent=1");
				if(!$requete)header("location:menu.php?ajoutevent1=0");
			} */
/*  SI PRELEMENT FAIT */
	/* if(isset($_GET['retour']) && $_GET['retour']!=NULL && $_GET['retour']==0) 
		$message = colorer("Vous devez rattacher un RIB au contrat","false"); */
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Intervenants sur le contrat</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=8" />
			<title><?php echo $titleGen ?></title>
			<link rel="stylesheet" type="text/css" href="../../css/main.css" />
            <link rel="stylesheet" type="text/css" href="list.css" />
			<!--[if IE 7]>
            	<link rel="stylesheet" type="text/css" href="../../css/ie7.css" />
            	<link rel="stylesheet" type="text/css" href="form_ie7.css" />
            <![endif]-->
			<!--[if IE 8]>
				<link rel="stylesheet" type="text/css" href="../../css/ie7.css" />
			<![endif]-->
			<script language="Javascript">
            <!--
                function modifier(choix){
                    var modifAct = document.getElementById("modifAct");id="modifActGp"
					var visuaAct = document.getElementById("VisuaAct");
                    modifAct.href = "detailintervenant.php?Identifiant_personne=" + choix;
					visuaAct.href = "detailintervenant.php?Identifiant_personne=" + choix + "&id=1";
                }
				function modifier2(choix, iContratId){
					var modifActGp = document.getElementById("modifActGp");
					var visuaActGp = document.getElementById("visuaActGp");
					modifActGp.href = "paiement/index.php?Identifiant_personne=" + choix + '&Identifiant_contrat=' + iContratId ;
					visuaActGp.href = "paiement/index.php?Identifiant_personne=" + choix + "&id=1&Identifiant_contrat=" + iContratId ;
				}
            //-->
            </script>
</head>

<body>
			<div id="sf_menu1">
				<h3>Production</h3>
				<?php
					require('../index.php');
					if(isset($message))
						echo $message;
					$nommodule="Modification administrative";
					$nommodule2="Liste des intervenants";
					$nom_module_saisie="Ecran saisie";
					?>
			</div>
			<div class="cleared"></div>
<div class="corps1">
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
<div class="form1">
	<span>N&#176; CONTRAT :</span>
      	<input class="resize_1" type="text" name="Numero_contrat" value="<?php if(isset($sess_con)) echo $sess_con; ?>" style="width:170px"  maxlength="20" />
        <div class="bt "><span class="btleft"></span><input type="submit" value="Rechercher" class="resizeall btmiddle" /><span class="btright"></span></div>
</div>
  <input type="hidden" name="MM_rechercher" value="form1" />
</form>
<div class="cleared"></div>
<div id="br"></div>
<!--/***************************************/-->
	<div class="imgleft2"></div>
	<div class="imgmiddle2">
		<div class="btn">
        	<span class="btnleft"></span>
            <span class="btnmiddle">
            	<h5><?php echo $nommodule; ?></h5>
            </span><span class="btnright"></span>
        </div>
		<div class="btn1">
        	<span class="btnleft"></span>
            <span class="btnmiddle">
            	<h5><?php echo $nommodule2; ?></h5>
            </span><span class="btnright"></span>
        </div>
		<div class="cleared" ></div>
		<div align=center>
		<span id="title" >INTERVENANTS SUR LE CONTRAT &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
		</div >
		<table class="tab_liste">
		  
		  <tr id="niv1">
		  	<td class="col1">&nbsp;</td>
		    <td class="col2">ROLE</td>
		    <td class="col3">TYPE ASSURE</td>
		    <td class="col4">NOM</td>
		    <td>PRENOM</td>
		  </tr>
		</table>
		
    	<div class="content_table bright">
<table class="tab_list">
  <?php 
if(isset($row_rs1['Identifiant_personne']) && !empty($row_rs1['Identifiant_personne']) && $etatContrat == 'A'){
  $i=1; do 	
  {
		mysql_select_db($database_microassur, $microassur);
		$query_rs_lab_personne = "SELECT * FROM personne WHERE Identifiant_personne = '". $row_rs1['Identifiant_personne'] ."'";
		$rs_lab_personne = mysql_query($query_rs_lab_personne, $microassur) or die(mysql_error());
		$row_rs_lab_personne = mysql_fetch_assoc($rs_lab_personne);
		$totalRows_rs_lab_personne = mysql_num_rows($rs_lab_personne);
		$idrol = $row_rs1['Identifiant_role'];
		$query_rs_id = mysql_query("SELECT DISTINCT(Identifiant_personne) FROM role WHERE Identifiant_personne = '". $row_rs1['Identifiant_personne'] ."' and Type_role='S'", $microassur) or die(mysql_error());
		$query_id =mysql_fetch_assoc($query_rs_id);
		if($query_id['Identifiant_personne']!=NULL)
			$var = $query_id['Identifiant_personne'];
		unset($_SESSION['idpers']);
		$_SESSION['idpers'] = $var;
		
		//medoune: REQUETE SUR LA TABLE DCTIONNAIE
		$reqdico = "Select DISTINCT(Identifiant_table) from dictionnaire where Code_table='M0003'";
		$rs_idtab_dico = mysql_query($reqdico, $microassur) or die(mysql_error());
		$row_idtab = mysql_fetch_assoc($rs_idtab_dico);
		
		//medoune: REQUETE SUR LA TABLE ELEMENTDICO
		$reqelmtdico = "Select DISTINCT(Nom_element) from elementdico where Identifiant_table='".$row_idtab['Identifiant_table']."'
		                and Code_element = '".$row_rs1['Type_assure']."'";
		$rs_elmtdico = mysql_query($reqelmtdico, $microassur) or die(mysql_error());
		$row_elmtdico = mysql_fetch_assoc($rs_elmtdico);
		
		$sReqRole = "select Nom_element from dictionnaire,elementdico where dictionnaire.Code_table='T0006' 
								and dictionnaire.Identifiant_table=elementdico.Identifiant_table 
								and Code_element = '".$row_rs1['Type_role']."'";
		$rsRole = mysql_query($sReqRole, $microassur) or die(mysql_error());
		$aRole = mysql_fetch_assoc($rsRole);
        
        if ($row_rs_lab_personne['Type_personne'] == TYPE_PERSONNE_MORALE )
        {
            $zNomOrRaisonSocial = $row_rs_lab_personne['Raison_sociale'] ;
        }
        else
        {
            $zNomOrRaisonSocial = $row_rs_lab_personne['Nom_personne'] ;
        }
        
  ?>
    <tr <?php if($i%2==0) echo 'class="colorligne"'; ?>>   
	  <td class="col1"><input onClick="modifier(this.value);" type="radio" name="choix" id="choix" value="<?php echo $row_rs1['Identifiant_personne']."&idrole=".$idrol; ?>" /></td>
      <td class="col2"><?php echo $aRole['Nom_element']; ?></td>
      <!--  >td class="col3"--><?php //echo $row_rs1['Type_assure']; ?><!-- /td-->
      <td class="col3"><?php  echo $row_elmtdico['Nom_element']; ?></td>
      <td class="col4"><?php echo $zNomOrRaisonSocial ; ?></td>
      <td><?php echo $row_rs_lab_personne['Prenom_personne']; ?></td>
    </tr>
    <?php
	$i++; } while ($row_rs1 = mysql_fetch_assoc($rs1)); 
	mysql_free_result($rs_lab_personne);
	}
	?>
</table>
		</div>
						<div id="buttonright"><span class="btleft"></span><span class="btmiddle"><a id="modifAct" href="#">Modifier</a></span><span class="btright"></span></div>
						<div id="buttonright"><span class="btleft"></span><span class="btmiddle"><a id="VisuaAct" href="#">Visualiser</a></span><span class="btright"></span></div>
<div class="bt1 check">
	<?php if(isset($_SESSION['idpers'])) { ?>
	<input onClick="modifier2(this.value, <?php echo $colname_rs1 ; ?>);" type="checkbox" name="paiement" id="paiement" value="<?php echo $_SESSION['idpers']; ?>"/> <span>PAIEMENT</span>
	<?php }else{ ?>
	<input type="checkbox" name="paiement" id="paiement" value=""/> <span>PAIEMENT</span>
	<?php } ?>
</div>
<div class="bt1 bn">
	<a id="modifActGp" href="#">
    	<span class="btleft"></span>
        <span class="btmiddle">Modifier</span>
        <span class="btright"></span>
    </a>

	<a id="visuaActGp" href="#">
    	<span class="btleft"></span>
        <span class="btmiddle">Visualiser</span>
        <span class="btright"></span>
    </a>
</div>
	</div>
	<div class="imgright2"></div>
	<div class="cleared"></div>
	<!--/******************ici*********************/-->


<!--<p align="center"><a href="index.php?retour=1">Retour</a></p>-->
<div class="cleared"></div>
<div class="bt1 retour">
	<a href="../../menu.php">
    	<span class="btleft"></span>
        <span class="btmiddle">Retour</span>
        <span class="btright"></span>
    </a>
</div>
<div class="cleared"></div>
<div id="br"></div>
</div>
</body>
</html>
<?php
//mysql_free_result($rs1);
 // Fin if(isset($row_rs1['Identifiant_personne']) && !empty($row_rs1['Identifiant_personne']))
ob_end_flush();
?>